﻿package view.popup
{
    import com.core.display.*;
    import com.sh.game.consts.*;
    import com.sh.game.global.*;
    import com.sh.game.util.*;
    import flash.display.*;
    import flash.events.*;
    import flash.net.*;
    import flash.text.*;
    import manager.*;
    import morn.core.components.*;

    public class NewDropDialogUI extends View implements IDialogUI
    {
        public var closeBtn:Button;
        public var sureBtn:Button;
        public var checkbox:CheckBox;
        protected var uiXML:XML;
        private var nametext:TextField;
        private var lesstext:TextField;
        private var _data:Object;
        private var item:Loader;
        private var tband:TextField;
        private var _func:Function = null;
        private var background:Sprite;

        public function NewDropDialogUI()
        {
            this.uiXML = <View>r
n	t	t	t	t	t  <Image url=""png.common.cs2_tsbg"" x=""0"" y=""0"" width=""300"" height=""185"" sizeGrid=""10,50,10,50""/>r
n	t	t	t	t	t  <Button skin=""png.common.btn_cs2_close"" x=""269"" y=""5"" var=""closeBtn""/>r
n	t	t	t	t	t  <Button skin=""png.common.btn_cs2_bag"" x=""110"" y=""144"" var=""sureBtn"" labelStroke=""1"" labelFont=""SimSun""/>r
n	t	t	t	t	t  <CheckBox label=""下次不提示"" skin=""png.common.checkbox_cs2_gx"" x=""22"" y=""120"" var=""checkbox"" labelColors=""0xb29a6c,0xb29a6c,0xb29a6c"" labelFont=""SimSun"" labelStroke=""1""/>r
n	t	t	t	t	t  <Image url=""png.common.img_2"" x=""22"" y=""36""/>r
n	t	t	t	t	t</View>")("<View>
					  <Image url="png.common.cs2_tsbg" x="0" y="0" width="300" height="185" sizeGrid="10,50,10,50"/>
					  <Button skin="png.common.btn_cs2_close" x="269" y="5" var="closeBtn"/>
					  <Button skin="png.common.btn_cs2_bag" x="110" y="144" var="sureBtn" labelStroke="1" labelFont="SimSun"/>
					  <CheckBox label="下次不提示\" skin="png.common.checkbox_cs2_gx" x="22" y="120" var="checkbox" labelColors="0xb29a6c,0xb29a6c,0xb29a6c" labelFont="SimSun" labelStroke="1"/>
					  <Image url="png.common.img_2" x="22" y="36"/>
					</View>;
            return;
        }// end function

        override protected function createChildren() : void
        {
            createView(this.uiXML);
            this.init();
            return;
        }// end function

        public function get data() : Object
        {
            return this._data;
        }// end function

        public function set data(param1:Object) : void
        {
            this._data = param1;
            return;
        }// end function

        override protected function initialize() : void
        {
            super.initialize();
            return;
        }// end function

        private function init() : void
        {
            this.background = new Sprite();
            this.background.graphics.beginFill(0, 0.5);
            this.background.graphics.drawRect(0, 0, GlobalLayer.instance.root.stage.stageWidth, GlobalLayer.instance.root.stage.stageHeight);
            this.background.graphics.endFill();
            this.background.addEventListener(MouseEvent.MOUSE_DOWN, this.onDown);
            PluginManager.instance.alertContainer.addChild(this.background);
            this.visible = false;
            this.x = GlobalLayer.instance.root.stage.stageWidth - this.width >> 1;
            this.y = GlobalLayer.instance.root.stage.stageHeight - this.height >> 1;
            this.nametext = new TextField();
            this.nametext.x = 100;
            this.nametext.y = 45;
            this.nametext.width = 200;
            this.nametext.height = 20;
            this.nametext.defaultTextFormat = new TextFormat("宋体", 12);
            this.nametext.textColor = 16777215;
            this.nametext.autoSize = TextFieldAutoSize.LEFT;
            this.addChild(this.nametext);
            this.lesstext = new TextField();
            this.lesstext.x = 100;
            this.lesstext.y = 84;
            this.lesstext.width = 180;
            this.lesstext.height = 20;
            this.lesstext.defaultTextFormat = new TextFormat("Verdata", 12);
            this.lesstext.text = "本组剩余:";
            this.lesstext.textColor = 16711680;
            this.lesstext.autoSize = TextFieldAutoSize.LEFT;
            this.addChild(this.lesstext);
            this.tband = new TextField();
            this.tband.x = 210;
            this.tband.y = 96;
            this.tband.defaultTextFormat = new TextFormat("宋体", 12);
            this.tband.autoSize = TextFieldAutoSize.LEFT;
            this.addChild(this.tband);
            this.checkbox.addEventListener(MouseEvent.CLICK, this.onRadio);
            this.sureBtn.label = "确认丢弃";
            this.sureBtn.labelColors = "0xb29a6c, 0xb29a6c, 0xb29a6c";
            this.sureBtn.labelFont = "宋体";
            this.sureBtn.addEventListener(MouseEvent.CLICK, this.onSure);
            this.closeBtn.addEventListener(MouseEvent.CLICK, this.onClose);
            this.addEventListener(MouseEvent.MOUSE_DOWN, this.onDown);
            GlobalLayer.instance.root.addEventListener(Event.RESIZE, this.resizeHandler);
            return;
        }// end function

        private function onSure(event:MouseEvent) : void
        {
            if (this._func != null)
            {
                this._func(this._data);
            }
            this.close();
            return;
        }// end function

        private function onRadio(event:MouseEvent) : void
        {
            this.checkbox.removeEventListener(MouseEvent.CLICK, this.onRadio);
            var _loc_2:* = event.currentTarget as CheckBox;
            this.checkbox.selected = false;
            _loc_2.selected = true;
            this.checkbox.addEventListener(MouseEvent.CLICK, this.onRadio2);
            return;
        }// end function

        private function onRadio2(event:MouseEvent) : void
        {
            this.checkbox.removeEventListener(MouseEvent.CLICK, this.onRadio2);
            var _loc_2:* = event.currentTarget as CheckBox;
            this.checkbox.selected = true;
            _loc_2.selected = false;
            this.checkbox.addEventListener(MouseEvent.CLICK, this.onRadio);
            return;
        }// end function

        public function show(param1:Object) : void
        {
            var _loc_2:String = "确认出售";
            this._data = param1[0];
            this._func = param1[1];
            if (param1[2])
            {
                _loc_2 = param1[2];
            }
            if (this.checkbox.selected)
            {
                if (this._func != null)
                {
                    this._func(this._data);
                    return;
                }
            }
            this.sureBtn.label = _loc_2;
            this.nametext.text = this._data[4].name;
            this.lesstext.htmlText = Html.covert("{FF0000#12#本组剩余:}") + Html.covert("{FF0000#12#" + this._data[1] + "}");
            if (this._data[4].bind == 1)
            {
                this.tband.text = "已绑定";
                this.tband.textColor = 16711680;
            }
            else
            {
                this.tband.text = "未绑定";
                this.tband.textColor = 65280;
            }
            this.darwItem();
            var _loc_3:Boolean = true;
            this.visible = true;
            this.background.visible = _loc_3;
            return;
        }// end function

        private function darwItem() : void
        {
            if (this.item)
            {
                this.item.parent.removeChild(this.item);
            }
            var imgURL:* = new URLRequest();
            imgURL.url = Config.getUrl("assets/images/icon/tools/" + this.data[4].icon + ".png", ResourceType.NORMAL);
            this.item = new Loader();
            this.item.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, function () : void
            {
                return;
            }// end function
            );
            this.item.load(imgURL);
            this.item.x = 28;
            this.item.y = 43;
            this.addChild(this.item);
            return;
        }// end function

        public function SpaceSure() : void
        {
            if (this.visible)
            {
                if (this._func != null)
                {
                    this._func(this._data);
                }
                this.close();
            }
            return;
        }// end function

        private function onClose(event:MouseEvent) : void
        {
            this.close();
            return;
        }// end function

        public function close() : void
        {
            var _loc_1:Boolean = false;
            this.visible = false;
            this.background.visible = _loc_1;
            this._data = null;
            this._func = null;
            this.nametext.text = "";
            return;
        }// end function

        private function onDown(event:MouseEvent) : void
        {
            event.stopImmediatePropagation();
            return;
        }// end function

        private function resizeHandler(event:Event) : void
        {
            this.background.width = GlobalLayer.instance.root.stage.stageWidth;
            this.background.height = GlobalLayer.instance.root.stage.stageHeight;
            this.x = GlobalLayer.instance.root.stage.stageWidth - this.width >> 1;
            this.y = GlobalLayer.instance.root.stage.stageHeight - this.height >> 1;
            return;
        }// end function

    }
}
